<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
    <th:block th:include="include :: header('国内经济发展列表')"/>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <div class="col-sm-12 search-collapse">
            <form id="formId" class="layui-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">主题：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="subject" placeholder="请输入主题"
                            class="layui-input" />
                    </div>
                    <label class="layui-form-label">内容：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="content" placeholder="请输入内容"
                            class="layui-input" />
                    </div>
                    <label class="layui-form-label">未来推演：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="futureDesc" placeholder="请输入未来推演"
                            class="layui-input" />
                    </div>
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="stockDomesDevelopHistory-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="stockDomesDevelopHistory-table" lay-filter="stockDomesDevelopHistory-table"></table>
        <script type="text/html" id="stockDomesDevelopHistory-toolbar">
            <button sec:authorize="hasPermission('/stock/stockDomesDevelopHistory/add','stock:stockDomesDevelopHistory:add')"
                    class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
                <i class="layui-icon layui-icon-add-1"></i>
                新增
            </button>
            <button sec:authorize="hasPermission('/stock/stockDomesDevelopHistory/remove','stock:stockDomesDevelopHistory:remove')"
                    class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
                <i class="layui-icon layui-icon-delete"></i>
                删除
            </button>
        </script>
        <script type="text/html" id="stockDomesDevelopHistory-bar">
            <button sec:authorize="hasPermission('/stock/stockDomesDevelopHistory/edit','stock:stockDomesDevelopHistory:edit')"
                    class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i
                    class="layui-icon layui-icon-edit"></i>
            </button>
            <button sec:authorize="hasPermission('/stock/stockDomesDevelopHistory/remove','stock:stockDomesDevelopHistory:remove')"
                    class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i
                    class="layui-icon layui-icon-delete"></i>
            </button>
        </script>
    </div>
</div>
<script id="stock-subjectType" type="text/html">
    {{#if (d.subjectType == 1) { }}
    <span>历史</span>
    {{# }else if(d.subjectType == 2){ }}
    <span>政治</span>
    {{# }else if(d.subjectType == 3){ }}
    <span>经济</span>
    {{# }else if(d.subjectType == 4){ }}
    <span>战争</span>
    {{# }else if(d.subjectType == 5){ }}
    <span>科技</span>
    {{# } }}
</script>

<script id="stock-type" type="text/html">
    {{#if (d.type == 1) { }}
    <span>未来</span>
    {{# }else if(d.type == 2){ }}
    <span>现实</span>
    {{# } }}
</script>
<th:block th:include="include :: footer"/>
<script>
    layui.use(['table', 'form', 'jquery', 'dictionary', 'popup'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let popup = layui.popup;

        let prefix = "/stock/stockDomesDevelopHistory/";

        let cols = [
            [
                {type: 'checkbox'},
                        {
                            field: 'id',
                            title: 'id(主键)'
                        },
                        {
                            field: 'subjectType',
                            title: '学科类型',
                            templet: '#stock-subjectType'
                        },
                        {
                            field: 'type',
                            title: '类别',
                            templet: '#stock-type'
                        },
                        {
                            field: 'subject',
                            title: '主题'
                        },
                        {
                            field: 'content',
                            title: '内容'
                        },
                        {
                            field: 'futureDesc',
                            title: '未来推演'
                        },
                {title: '操作', toolbar: '#stockDomesDevelopHistory-bar', align: 'center', width: 130}
            ]
        ]

        table.render({
            elem: '#stockDomesDevelopHistory-table',
            url: prefix + 'data',
            page: true,
            cols: cols,
            skin: 'line',
            toolbar: '#stockDomesDevelopHistory-toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports']
        });

        table.on('tool(stockDomesDevelopHistory-table)', function (obj) {
            if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'edit') {
                window.edit(obj);
            }
        });

        table.on('toolbar(stockDomesDevelopHistory-table)', function (obj) {
            if (obj.event === 'add') {
                window.add();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'batchRemove') {
                window.batchRemove(obj);
            }
        });

        form.on('submit(stockDomesDevelopHistory-query)', function (data) {
            table.reload('stockDomesDevelopHistory-table', {where: data.field})
            return false;
        });

        window.add = function () {
            layer.open({
                type: 2,
                title: '新增国内经济发展',
                shade: 0.1,
                area: ['550px', '500px'],
                content: prefix + 'add'
            });
        }

        window.edit = function (obj) {
            layer.open({
                type: 2,
                title: '修改国内经济发展',
                shade: 0.1,
                area: ['550px', '500px'],
                content: prefix + 'edit?id=' + obj.data['id']
            });
        }

        window.remove = function (obj) {
            layer.confirm('确定要删除该国内经济发展', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: prefix + "remove/" + obj.data['id'],
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.success) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                obj.del();
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        window.batchRemove = function (obj) {
            let data = table.checkStatus(obj.config.id).data;
            if (data.length === 0) {
                layer.msg("未选中数据", {icon: 3, time: 1000});
                return false;
            }
            let ids = "";
            for (let i = 0; i < data.length; i++) {
                ids += data[i].id + ",";
            }
            ids = ids.substr(0, ids.length - 1);
            layer.confirm('确定要删除这些国内经济发展', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: prefix + "batchRemove",
                    dataType: 'json',
                    data: {"ids": ids},
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.success) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                table.reload('stockDomesDevelopHistory-table');
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        window.refresh = function (param) {
            table.reload('stockDomesDevelopHistory-table', {where: param});
        }


    })
</script>
</body>
</html>